package com.jy.wms.controller;

import com.joyi.gate.comm.SessionInfo;
import com.joyi.gate.safety.vo.UserInfo;
import com.jy.wms.common.SetStatus;
import com.jy.wms.common.base.*;
import com.jy.wms.pojo.WmsCustomerFileConsignee;
import com.jy.wms.pojo.WmsOwner;
import org.apache.ibatis.annotations.Delete;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.jy.wms.pojo.WmsSplit;
import com.jy.wms.service.WmsSplitService;
import javax.servlet.http.HttpSession;
import com.github.pagehelper.Page;

import java.util.List;
import java.util.Map;

import com.jy.wms.common.UUIDUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * @ClassName: WmsSplitController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author Liyi
 * @Date Tue Oct 24 15:29:46 CST 2017
 */
@RestController
@RequestMapping("/wmsSplit")
@Api(value = "/wmsSplit", description = "关于拆单操作")
public class  WmsSplitController extends BaseController<WmsSplitService,WmsSplit> {

    @ApiOperation(value = "拆单操作  拆单",response = JSONObject.class, notes = "拆单，'ssfyddid'所属发运订单ID")
    @PostMapping(value = "/split")
    public @ResponseBody
    JSONObject split(HttpSession session ,@RequestBody SetAndModifyModel setAndModifyModel) {
        JSONObject json = getJSONObject();
        try {
            UserInfo userinfo= (UserInfo) session.getAttribute(SessionInfo.USER_INFO);
            baseService.split(setAndModifyModel,userinfo.getUser().getName(),String.valueOf(userinfo.getUser().getOrgId().get(0)));
        } catch (SucessException e) {
            json = SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"拆单成功",e.getMessage(), "");
        }catch (Exception e) {
            e.printStackTrace();
            json = SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"拆单失败",e.getMessage(), "");
        }
        return json;
    }

    @ApiOperation(value = "拆单操作  取消拆单",response = JSONObject.class, notes = "取消拆单，'ssfyddid'所属发运订单ID")
    @PostMapping(value = "/cancel")
    public @ResponseBody
    JSONObject cancel(HttpSession session ,@RequestBody SetAndModifyModel setAndModifyModel) {
        JSONObject json = getJSONObject();
        try {
            UserInfo userinfo= (UserInfo) session.getAttribute(SessionInfo.USER_INFO);
            baseService.baseDeleteBySsfyddid(setAndModifyModel,userinfo.getUser().getName(),String.valueOf(userinfo.getUser().getOrgId().get(0)));
        } catch (SucessException e) {
            json = SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"取消拆单成功",e.getMessage(), "");
        }catch (Exception e) {
            e.printStackTrace();
            json = SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"取消拆单失败","未拆单订单不可取消拆单", "");
        }
        return json;
    }

    @ApiOperation(value = "拆单操作  查看拆单明细",response = JSONObject.class, notes = "查看拆单明细，'ssfyddid'所属发运订单ID")
    @PostMapping(value = "/list")
    public @ResponseBody
    JSONObject cancel(HttpSession session ,@RequestBody WmsSplit entity) {
        JSONObject json = getJSONObject();
        try {
            UserInfo userinfo= (UserInfo) session.getAttribute(SessionInfo.USER_INFO);
            entity.setCkid(String.valueOf(userinfo.getUser().getOrgId().get(0)));
            Page<Map<String,Object>> list = baseService.baseSelectPage(entity);
            json = SetStatus.setSearchType(JSONArray.fromObject(list).toString(),(int) list.getTotal());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }

}
